package cn.wolfcode.trip.base.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 动态内容
 */
@Getter
@Setter
@JsonIgnoreProperties("handler")
public class DynamicContent extends BaseDomain{
    //内容
    private String content;
    //发布者
    private User release;
    //内容图片
    private String imgUrls;
    // 发布者位置
    private String position;
    //时间
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date createTime;
    //点赞人集合
    private List<FriendPraise> friendPraises;
    //点赞人字符串
    private String friendPraisesString;

    //获取点赞人数量
    public int getFriendPraisesCount(){
        int count = 0;
        if(friendPraises!=null){
            count = friendPraises.size();
        }
        return count;
    }

    //获取评论图片url
    public String[] getImgArr(){
        if (StringUtils.hasLength(imgUrls)) {
            return imgUrls.split(";");
        }
        return null;
    }
}